home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d21 / dvglue10.arc / UIWOPEN.C < prev    next >
C/C++ Source or Header  |  1988-08-13  |  5KB  |  163 lines

  1. /*======================================================*/
  2. /*  UIWOPEN.C                                           */
  3. /*                                                      */
  4. /* (c) Copyright 1988 Ralf Brown.  All Rights Reserved. */
  5. /*======================================================*/
  6.  
  7. #include <bios.h>
  8. #include "tvapi.h"
  9. #include "tvui.h"
  10.  
  11. /*================================================*/
  12. /*================================================*/
  13.  
  14. static void pascal near box(OBJECT win,int rows,int cols)
  15. {
  16.    int attr = TVqry_logattr(win)?9:135 ;
  17.    int i ;
  18.  
  19.    TVwin_cursor(win,0,0) ;
  20.    TVputchar(win,'╔',attr) ;
  21.    for (i = 0 ; i < cols ; i++)
  22.       TVputchar(win,'═',attr) ;
  23.    TVputchar(win,'╗',attr) ;
  24.    for (i = 1 ; i <= rows ; i++)
  25.       {
  26.       TVwin_cursor(win,i,0) ;
  27.       TVputchar(win,'║',attr) ;
  28.       TVwin_cursor(win,i,cols+1) ;
  29.       TVputchar(win,'║',attr) ;
  30.       }
  31.    TVwin_cursor(win,rows+1,0) ;
  32.    TVputchar(win,'╚',attr) ;
  33.    for (i = 0 ; i < cols ; i++)
  34.       TVputchar(win,'═',attr) ;
  35.    TVputchar(win,'╝',attr) ;
  36.    TVwin_cursor(win,0,0) ;
  37. }
  38.  
  39. /*================================================*/
  40. /* UIwin_open  allow user to choose size and loc  */
  41. /*             of a window which is to be opened  */
  42. /*   Ralf Brown 7/29/88                           */
  43. /*================================================*/
  44.  
  45. OBJECT pascal UIwin_open(OBJECT parent,int minrows,int mincols,
  46.                          int maxrows,int maxcols, int defrows,int defcols)
  47. {
  48.    OBJECT p, w, mw ;
  49.    int row, col ;
  50.    int rows, cols ;
  51.    POINTER_MSG msg ;
  52.    int new_message ;
  53.    int left_button = FALSE, right_button = FALSE ;
  54.  
  55.    if (minrows < 0) minrows = 0 ;
  56.    if (mincols < 0) mincols = 0 ;
  57.    if (defrows < minrows) defrows = minrows ;
  58.    if (defcols < mincols) defcols = mincols ;
  59.    if ((w = TVwin_new(parent,defrows>5?defrows:5,defcols>9?defcols:9)) == NIL)
  60.       return NIL ;
  61.    if ((p = TVptr_new()) == NIL)
  62.       {
  63.       TVwin_free(w) ;
  64.       return NIL ;
  65.       }
  66.    if ((mw = TVwin_new(parent,1,32)) != NIL)
  67.       {
  68.       TVwin_title(mw,"Open Window") ;
  69.       TVwin_move(mw,1,1) ;
  70.       TVwin_cursor(mw,0,0) ;
  71.       TVwin_swrite(mw,"Drag window to desired position") ;
  72.       TVwin_topsys(mw) ;
  73.       }
  74.    TVptr_open(p,w) ;
  75.    if (TVqry_kmouse())
  76.       TVapi_kmouse(TRUE) ;
  77.    TVptr_setflags(p,PTR_RELEASE | PTR_HIDDEN | PTR_ABSOLUTE) ;
  78.    TVqry_position(parent,&row,&col) ;
  79.    TVptr_goto(p,row+defrows/2,col+defcols/2) ;
  80.    TVptr_clrflags(p,PTR_ABSOLUTE) ;
  81.    TVwin_clear(w) ;
  82.    TVwin_cursor(w,0,0) ;
  83.    TVwin_move(w,row,col) ;
  84.    /* use reverse video frame if logical attributes, blinking if physical */
  85.    TVwin_frattr(w,TVqry_logattr(w)?9:143) ;
  86.    TVwin_top(w) ;
  87.    new_message = FALSE ;
  88.    do {
  89.       TVptr_read(p,&msg) ;
  90.       if (!new_message && mw)
  91.          {
  92.          new_message = TRUE ;
  93.          TVwin_cursor(mw,0,0) ;
  94.          TVwin_swrite(mw,"Left button: done Right: cancel") ;
  95.          TVwin_redraw(mw) ;
  96.          }
  97.       row += msg.row - defrows/2 ;
  98.       col += msg.column - defcols/2 ;
  99.       if (msg.button_state == 0x81)
  100.          left_button = TRUE ;
  101.       else if (msg.button_state == 0x82)
  102.          right_button = TRUE ;
  103.       TVwin_move(w,row,col) ;
  104.       TVwin_redraw(w) ;
  105.       } while (!left_button && !right_button) ;
  106.    if (right_button)
  107.       {
  108.       TVwin_free(mw) ;
  109.       TVwin_free(w) ;
  110.       TVptr_free(p) ;
  111.       if (TVqry_kmouse())
  112.          TVapi_kmouse(FALSE) ;
  113.       return NIL ;
  114.       }
  115.    rows = defrows ;
  116.    cols = defcols ;
  117.    if (mw)
  118.       {
  119.       TVwin_cursor(mw,0,0) ;
  120.       TVwin_swrite(mw,"Size window and click button   ") ;
  121.       TVwin_redraw(mw) ;
  122.       }
  123.    TVptr_setflags(p,PTR_ABSOLUTE) ;
  124.    TVptr_goto(p,row+rows,col+cols) ;
  125.    TVwin_frame(w,FALSE) ;
  126.    TVwin_move(w,row-1,col-1) ;
  127.    TVwin_lsize(w,rows+4,cols+7) ;
  128.    TVwin_resize(w,rows+4,cols+7) ;
  129.    box(w,rows,cols) ;
  130.    TVwin_redraw(w) ;
  131.    do {
  132.       TVptr_read(p,&msg) ;
  133.       rows = msg.row-row ;
  134.       cols = msg.column-col ;
  135.       if (rows >= minrows && cols >= mincols)
  136.          {
  137.          TVwin_lsize(w,rows+4,cols+7) ;
  138.          TVwin_resize(w,rows+4,cols+7) ;
  139.          TVwin_clear(w) ;
  140.          box(w,rows,cols) ;
  141.          TVwin_redraw(w) ;
  142.          }
  143.       } while ((msg.button_state & 0x41) != 0x41) ; /* until left button is released */
  144.    TVwin_clear(w) ;
  145.    TVwin_lsize(w,rows,cols) ;
  146.    TVwin_resize(w,rows,cols) ;
  147.    TVwin_move(w,row,col) ;
  148.    TVwin_frame(w,TRUE) ;
  149.    if (TVqry_kmouse())
  150.       TVapi_kmouse(FALSE) ;
  151.    TVptr_free(p) ;
  152.    TVwin_free(mw) ;
  153.    if (rows > maxrows)
  154.       rows = maxrows ;
  155.    if (cols > maxcols)
  156.       cols = maxcols ;
  157.    TVwin_resize(w,rows,cols) ;
  158.    TVwin_frattr(w,TVqry_logattr(w)?1:7) ;
  159.    return w ;
  160. }
  161.  
  162. /* End of UIWOPEN.C */
  163.